package com.focusai.efairy.model.request;

import com.focusai.efairy.model.dev.UpLoadDeviceEntity;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.PureJSONRequest;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

/**
 * Created by luo_guangwen on 2017/8/13.
 */

public class AddDeviceRequest extends PureJSONRequest<String> {
    private UpLoadDeviceEntity upLoadDeviceEntity;

    public AddDeviceRequest(UpLoadDeviceEntity deviceEntity, Response.Listener<String> listener) {
        super(UrlUtils.createUrl("/appapi/manage_project_device"), listener);
        this.upLoadDeviceEntity = deviceEntity;
    }

    @Override
    protected String parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<String>() {
        }.getType());
    }

    @Override
    public String getPureJSON() throws JSONException {
        if (upLoadDeviceEntity != null) {
            return GsonHelper.getInstance().toJson(upLoadDeviceEntity);
        }
        return null;
    }
}
